package com.wuwei.business.controller;

import com.wuwei.business.VO.RentVo;
import com.wuwei.business.service.BusAttachmentService;
import com.wuwei.business.service.IBusCarService;
import com.wuwei.business.service.IBusCustomerService;
import com.wuwei.common.core.controller.BaseController;
import com.wuwei.common.core.domain.AjaxResult;
import com.wuwei.common.core.domain.model.LoginUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 内容: SSM
 * 作者: weishao
 */
@RestController
@RequestMapping("business/rentCar")
public class RentCarController extends BaseController {
     @Autowired
    private IBusCustomerService busCustomerService;
    @Autowired
    private IBusCarService carService;
     @Autowired
    private BusAttachmentService attachmentService;

    /**
     * 通过身份证查表是否登记
     * @param identity 身份证号
     * @return
     */
     @GetMapping("checkCustomerId")
    public AjaxResult checkCustomerId(String identity){
         Integer i=busCustomerService.checkCustomerId(identity);
         return toAjax(i);
     }

    /**
     * 查询图片地址
     * @param carNumber 车牌号
     * @return
     */
     @GetMapping("showCarImgs")
    public AjaxResult showCarImgs(String carNumber){
         List<String> carImags =attachmentService.selectCarImags(carNumber);
         return AjaxResult.success(carImags);
     }

    /**
     * 回显数据
     * @param carId 车的ID
     * @return
     */
    @GetMapping("toRent")
    public AjaxResult toRent(Long carId){
          RentVo rentVo =carService.toRent(carId);
          return AjaxResult.success(rentVo);
    }

    /**
     * JSON风格把数据显示
     * @param rentVo 取表单需要的值
     * @return
     */
    @PostMapping("doRent")
    public AjaxResult doRent(@RequestBody RentVo rentVo){
        LoginUser loginUser = getLoginUser();
        Boolean flag=carService.realDoRent(rentVo,loginUser);
        return AjaxResult.success(flag?"租车成功":"租车失败");
    }
}
